import { getAdminApi } from "@/api/adminManage";
import { getCouponApi, getCouponSendWayApi } from "@/api/coupon";
import { getPermissionApi } from "@/api/permissionManage";
import { getRoleApi } from "@/api/roleManage";
import { getGroupTypeApi, getUserGroupApi } from "@/api/userGroup";
import { getUserLabelApi, type userLabelItemLimit } from "@/api/userLabel";
import { getUserLevelApi, type userLevelItemLimit } from "@/api/userLevel";
import { getUserTagByLabelApi } from "@/api/userTag";
import { getUserTypeApi } from "@/api/userType";
import { reactive } from "vue";



export function useFindData() {

    const userLevelData = reactive<{ rows: userLevelItemLimit[], total: number }>({ rows: [], total: 0 });
    const userGroupData = reactive<any>({ rows: [], total: 0 });
    const userLabelData = reactive<{ rows: userLabelItemLimit[], total: number }>({ rows: [], total: 0 });
    const couponData = reactive<{ rows: userLabelItemLimit[], total: number }>({ rows: [], total: 0 });
    const couponSendWayData = reactive<any>({ rows: [], total: 0 });
    const userTagByLabelData = reactive<any>({ data: [], });
    const userTypeData = reactive<any>({ rows: [], total: 0 });
    const groupTypeData = reactive<any>({ rows: [], total: 0 });
    const permissionData = reactive<any>({ rows: [], total: 0 });
    const roleData = reactive<any>({ rows: [], total: 0 });
    const adminData = reactive<any>({ rows: [], total: 0 });
    function getUserLevelJoint(params?: object) {
        getUserLevelApi(params).then(res => {
            if (res.code == 200) {
                userLevelData.rows = res.data.rows;
                userLevelData.total = res.data.total;
            }
        })
    }
    function getUserGroupApiJoint(params?: object) {
        getUserGroupApi(params).then(res => {
            if (res.code == 200) {
                userGroupData.rows = res.data.rows;
                userGroupData.total = res.data.total;
            }
        })

    }
    function getUserLabelJoint(params?: object) {
        getUserLabelApi(params).then(res => {
            if (res.code == 200) {
                userLabelData.rows = res.data.rows;
                userLabelData.total = res.data.total;
            }
        })
    }
    function getUserTagByLabelJoint(params?: object) {
        getUserTagByLabelApi(params).then(res => {
            if (res.code == 200) {
                userTagByLabelData.data = res.data;
            }
        })
    }
    function getCouponJoint(params?: object) {
        getCouponApi(params).then(res => {
            if (res.code == 200) {
                couponData.rows = res.data.rows;
                couponData.total = res.data.total;
            }
        })
    }
    function getCouponSendWayJoint(params?: object) {
        getCouponSendWayApi(params).then(res => {
            if (res.code == 200) {
                couponSendWayData.rows = res.data.rows;
                couponSendWayData.total = res.data.total;
            }
        })
    }

    function getUserTypeJoint(params?: object) {
        getUserTypeApi(params).then(res => {
            if (res.code == 200) {
                userTypeData.rows = res.data.rows;
                userTypeData.total = res.data.total;
            }
        })
    }
    function getGroupTypeJoint(params?: object) {
        getGroupTypeApi(params).then(res => {
            if (res.code == 200) {
                groupTypeData.rows = res.data.rows;
                groupTypeData.total = res.data.total;
            }
        })
    }
    function getPermissionJoint(params?: object) {
        getPermissionApi(params).then(res => {
            if (res.code == 200) {
                permissionData.rows = res.data.rows;
                permissionData.total = res.data.total;
            }
        })
    }
    function getRoleJoint(params?: object) {
        getRoleApi(params).then(res => {
            if (res.code == 200) {
                roleData.rows = res.data.rows;
                roleData.total = res.data.total;
            }
        })
    }
    function getAdminJoint(params?: object) {
        getAdminApi(params).then(res => {
            if (res.code == 200) {
                adminData.rows = res.data.rows;
                adminData.total = res.data.total;
            }
        })
    }



    return {
        userLevelData, getUserLevelJoint, userGroupData, getUserGroupApiJoint,
        userLabelData, getUserLabelJoint, userTagByLabelData, getUserTagByLabelJoint, couponData, getCouponJoint,
        couponSendWayData, getCouponSendWayJoint, userTypeData, getUserTypeJoint, groupTypeData, getGroupTypeJoint,
        permissionData, getPermissionJoint, roleData, getRoleJoint, adminData, getAdminJoint
    }
}